<template>
    <div class="wrap">
        <a-select style="width: 100%;" :options="optionsList" @change="onChange" :value="value"
            :placeholder="placeholderInfo || '请选择'"></a-select>
    </div>
</template>
<script>
import moment from 'moment';
export default {
    name: 'ZsData',
    props: {
        menuId: {
            type: [String, Number],
            default: 2,
        },
        formData: {
            type: Object,
            default: () => { }
        },
        dataIndex: {
            type: String,
            default: 'data',
        },
        onCallBack: {
            type: Function,
            default: () => { }
        },
        allowClear: {
            type: Boolean,
            default: true,
        },
        staticOptionList: {
            type: [Object, Array],
            default: [],
        },
        placeholderInfo: {
            type: String,
        }
    },
    data() {
        return {
            optionsList: [],
            value: '',
        }
    },
    mounted() {
        if (this.staticOptionList.length > 0) {
            this.optionsList = this.staticOptionList
        } else {
            this.getList();
        }
    },
    methods: {
        onChange(v) {
            this.value = v;
            this.onCallBack(v, this.dataIndex);
        },
        getList() {
            this.getAxios(this.$getDeptSelect, {})
                .then((res) => {
                    if (res.code == 200) {
                        this.optionsList = res.data.map(val => {
                            return {
                                ...val,
                                label: val.name,
                                value: val.id,
                            }
                        });
                    }
                })
                .catch(() => { })
                .finally(() => {
                });
        },
    },
    computed: {
    },
    watch: {
        menuId: {
            handler() {
            },
            immediate: true,
            deep: true,
        },
        formData: {
            handler(nVal, oVal) {
                this.value = nVal[this.dataIndex]
            },
            deep: true,
            immediate: true,
        }
    }
}
</script>
<style lang="less" scoped>
.wrap {
    width: 160px;
}
</style>